const axios = require('axios')

/*
* request(config)
* get(url, conifg)
* delete(url, conifg)
* post(url, data, config)
* head(url, config)
* put(url, data, config)
* patch(url, data, config)
* 更多使用: https://segmentfault.com/a/1190000008470355
* */



axios.get('https://jsonplaceholder.typicode.com/todos/1')
.then(function (response) {
    console.log('then:', response)
}).catch(function (error) {
    console.log('error:',error)
})

// 更多参数
// 发起post请求
axios({
    method: 'post',
    url: '/user/12345',
    data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
    }
})

// 获取远程图片
axios({
    method: 'get',
    url: 'http://bit.ly/2mTM3nY',
    responseType:'stream'
}).then(function (response) {
    response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
})




